﻿<Window x:Class="StockAnalyst2.MainWindow"
		x:ClassModifier="internal"
		
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		mc:Ignorable="d"
		
		xmlns:SA2="clr-namespace:StockAnalyst2"
		xmlns:StockGrid="clr-namespace:StockAnalyst2.StockGrid" 
		xmlns:Converters="clr-namespace:Utils.Wpf.Converters;assembly=Utils"
        xmlns:TaskbarNotification="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification"
        xmlns:Historical="clr-namespace:StockAnalyst2.Plugins.Visualization.Historical"
        xmlns:Realtime="clr-namespace:StockAnalyst2.Plugins.Visualization.Realtime"
        xmlns:Chart="clr-namespace:StockAnalyst2.Chart" 
		
		Title="Stock Analyst 2"
		ResizeMode="CanResize" 
		WindowStartupLocation="CenterScreen"
		ShowInTaskbar="{Binding MainWindowStateVM.IsVisible}"
        WindowState="{Binding MainWindowStateVM.State, Mode=TwoWay}" 
		
		Icon="/StockAnalyst2;component/Resources/Main.ico"
		
		Closing="Window_Closing" 
		Background="Black"
		
		x:Name="MainUI"
		
		d:DesignHeight="400"
		d:DesignWidth="1400"
		d:DataContext="{d:DesignInstance Type=SA2:MainWindowVM}" >

	<Window.Resources>
		<ResourceDictionary>
			<ContextMenu x:Key="IconMenu" Opened="ContextMenu_Opened"> <!-- Is set as a resource to initialize it before setting it to the notify icon -->
				<MenuItem Header="View" Command="{Binding MainWindowStateVM.MaximizeCommand}" />
				<MenuItem Header="Enable Real Time Capture" IsCheckable="True" Command="{Binding ApplicationCommandsVM.ChangeCaptureRealTimeStatusCommand, UpdateSourceTrigger=PropertyChanged}" IsChecked="{Binding MainToolBarVM.IsRealtimeEnabled, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" />
				<Separator/>
				<MenuItem Header="Exit" Command="{Binding ApplicationCommandsVM.ExitCommand}" />
			</ContextMenu>
			<Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="StockAnalystTheme.xaml" />
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</Window.Resources>

	<Window.Visibility>
		<Binding Path="MainWindowStateVM.IsVisible"	Converter="{StaticResource BooleanToVisibilityConverter}" />
	</Window.Visibility>
	
	<Grid x:Name="MainGrid" >
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
			<RowDefinition Height="*" />
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>
		
		<!-- Taskbar Icon -->
		<TaskbarNotification:TaskbarIcon VerticalAlignment="Top" IconSource="Resources/Main.ico" DoubleClickCommand="{Binding MainWindowStateVM.MaximizeCommand}" Visibility="{Binding MainWindowStateVM.IsIconVisible}" ContextMenu="{StaticResource IconMenu}" />

		<!-- Menu -->
		<Menu Grid.Row="0" IsMainMenu="True" >
			<MenuItem Header="File" >
				<MenuItem Header="Enable Real Time Capture" IsCheckable="True" Command="{Binding ApplicationCommandsVM.ChangeCaptureRealTimeStatusCommand, UpdateSourceTrigger=PropertyChanged}" IsChecked="{Binding MainToolBarVM.IsRealtimeEnabled, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" />
				<MenuItem Header="Exit" Command="{Binding ApplicationCommandsVM.ExitCommand}" />
			</MenuItem>
			<MenuItem Header="View" >
				<MenuItem Header="Real Time Data" IsCheckable="True" Command="{Binding ApplicationCommandsVM.ViewRealTimeDataCommand}" IsChecked="{Binding MainToolBarVM.IsRealTimeViewSelected, Mode=OneWay}" />
				<MenuItem Header="Historical Data" IsCheckable="True" Command="{Binding ApplicationCommandsVM.ViewHistoricalDataCommand}" IsChecked="{Binding MainToolBarVM.IsHistoricalViewSelected, Mode=OneWay}" />
				<Separator/>
				<MenuItem Header="RealTime Plugins" IsCheckable="True" Command="{Binding ApplicationCommandsVM.ViewRealtimePluginsCommand}" IsChecked="{Binding MainToolBarVM.IsRealtimePluginsViewSelected, Mode=OneWay}" />
				<MenuItem Header="Historical Plugins" IsCheckable="True" Command="{Binding ApplicationCommandsVM.ViewHistoricalPluginsCommand}" IsChecked="{Binding MainToolBarVM.IsHistoricalPluginsViewSelected, Mode=OneWay}" />
				<Separator/>
				<MenuItem Header="Charts" IsCheckable="True" Command="{Binding ApplicationCommandsVM.ViewChartCommand}" IsChecked="{Binding MainToolBarVM.IsChartViewSelected, Mode=OneWay}" />
			</MenuItem>
			<MenuItem Header="Plugins" x:Name="PluginsMenu" IsEnabled="{Binding MainToolBarVM.IsHistoricalPluginsViewSelected}" />
			<MenuItem Header="Tools" >
				<MenuItem Header="Grid Options" Command="{Binding ApplicationCommandsVM.GridOptionsCommand}" />
				<MenuItem Header="Options" Command="{Binding ApplicationCommandsVM.OptionsCommand}" />
				<MenuItem Header="Open Browser" Command="{Binding ApplicationCommandsVM.OpenBrowserCommand}" />
			</MenuItem>
		</Menu>
		
		<!-- Toolbar -->
		<SA2:MainToolBar Grid.Row="1" DataContext="{Binding MainToolBarVM}" x:Name="MainToolBar" />
		
		<!-- Up Border Decorator -->
		<Border Grid.Row="2" Background="{StaticResource TopbarBackground}" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLine}" />

		<!-- Historical grid -->
		<StockGrid:GridViewer Grid.Row="3" DataContext="{Binding HistoricalGridVM}" Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" />

		<!-- Realtime Plugin viewer -->
		<Realtime:RealtimePluginViewer Grid.Row="3" DataContext="{Binding RealtimePluginViewerVM}" Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}" />

		<!-- Historical Plugin viewer -->
		<Historical:HistoricalPluginViewer Grid.Row="3" DataContext="{Binding HistoricalPluginViewerVM}" Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />

		<!-- Chart viewer -->
		<Chart:ChartViewer Grid.Row="3" DataContext="{Binding ChartViewerVM}" Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed, TargetNullValue=Collapsed}" />

		<!-- Realtime grid -->
		<StockGrid:GridViewer Grid.Row="3" DataContext="{Binding RealTimeGridVM}" Visibility="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Visible}" />
		
		<!-- Down Border Decorator -->
		<Border Grid.Row="4" Background="{StaticResource DownbarBackground}" BorderThickness="0,0,0,1" BorderBrush="#688CAF" />

		<!-- StatusBar -->
		<SA2:MainStatusBar Grid.Row="5" DataContext="{Binding MainStatusBarVM}" />
	</Grid>
</Window>
